package validators

import (
	"wskyygyso/api/pkg/captcha"
	"wskyygyso/api/pkg/verifycode"
)

// ValidatePasswordConfirm 自定义规则，检查两次密码是否正确
func ValidatePasswordConfirm(password, passwordConfirm string, errs map[string][]string) map[string][]string {
	if password != passwordConfirm {
		errs["password_confirm"] = append(errs["password_confirm"], "两次输入密码不匹配！")
	}
	return errs
}

func ValidateCaptcha(captchaId string, captchaAnswer string, err map[string][]string) map[string][]string {
	if ok := captcha.NewCaptcha().VerifyCaptcha(captchaId, captchaAnswer); !ok {
		err["captcha_answer"] = append(err["captcha_answer"], "验证码错误")
	}
	return err
}

func ValidateVerifyCode(captchaId string, captchaAnswer string, err map[string][]string) map[string][]string {
	if ok := verifycode.NewVerifyCode().Store.Verify(captchaId, captchaAnswer, false); !ok {
		err["verify_code"] = append(err["verify_code"], "验证码错误")
	}
	return err
}
